<template>
  <van-tab title="评论">
    <div class="course-comment">
      <Empty v-show="comments.length == 0"></Empty>
      <div class="comment-item" v-for="item in comments">
        <div class="info">
          <div class="user">
            <div class="avatar"><img v-lazy="user[item.user_id].avatar" alt=""></div>
            <div class="nickname">{{user[item.user_id].nick_name}}</div>
          </div>
          <div class="time">{{item.created_at | formatTime}}</div>
        </div>
        <div class="text" style="padding-left: 36px;">{{item.render_content}}</div>
      </div>
    </div>
    <van-goods-action>
      <van-field
        v-model="content"
        center
        placeholder="请输入评论内容"
      >
        <template #button>
          <van-button size="small" @click="content && sendRemark()" :class="{hasvalue: content}">发布</van-button>
        </template>
      </van-field>
    </van-goods-action>
  </van-tab>
</template>

<script>
import Empty from '@/components/common/Empty';
import { Notify } from 'vant';

export default {
  components: {
    Empty,
  },
  props: ['comments', 'user'],
  data() {
    return {
      content: '',
    };
  },
  methods: {
    sendRemark() {
      if (!this.$store.state.user.isLogin) return Notify('请先登录');
      this.$emit('comment', this.content);
    },
  },
};
</script>

<style lang="less" scoped>
.course-comment {
  .comment-item {
    padding: 0 16px;
    height: 80px;
    .info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 12px 0 8px;
      font-size: 12px;
      color: #999;
      .user {
        display: flex;
        align-items: center;
      }
      .avatar {
        margin-right: 6px;
        img {
          width: 32px;
          height: 32px;
          border-radius: 50%;
        }
      }
    }
  }
}
</style>
